<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>业务单位新增</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
    <style>
        .expand.pear-btn:hover {
            color: currentColor;
            background: none;
        }

        .expand.pear-btn {
            border: 1px solid rgba(255, 255, 255, 0)
        }
        .layui-textarea{
        /*height: 5px!important;*/
        min-height: 60px!important;
       
 }
 .layui-tc{
    max-width: 810px;
 }

    </style>
</head>

<body class="pear-container">
    <div class="layui-tab-item layui-show">
        <form class="layui-form" action="" onsubmit="return false">
          <div class="layui-bg-gray" style="padding: 30px;">
            <div class="layui-row layui-col-space15">
              <div class="layui-col-md12">
                <div class="layui-card">
                  <div class="layui-card-header">基础资料</div>
                  <div class="layui-card-body">
                    <div class="layui-form-item">
                      <label class="layui-form-label">单位名称</label></label>
                      <div class="layui-input-inline">
                        <input type="text" name="unitName" id="unitName" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
                        <input type="text" name="id" id="id" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
                      </div>
                      <label class="layui-form-label">单位简称</label>
                      <div class="layui-input-inline">
                        <input type="text" name="unitNameJp" id="unitNameJp" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
                      </div>
                      <label class="layui-form-label">产品分类</label>
                      <div class="layui-input-inline">
                        <select name="category" id="category" lay-verify="">
                            <option value="-1" selected>全部</option>
                            <option value="0">供应商/客户</option>
                            <option value="1">供应商</option>
                            <option value="2">客户</option>
                        </select>
                        <!-- <input type="text" id="tree" lay-filter="tree" class="layui-input"> -->
                      </div>     
                    </div>
                    <div class="layui-form-item">
                      <label class="layui-form-label">电话</label>
                    <div class="layui-input-inline">
                      <input type="text" name="companyPhone" id="companyPhone" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
                    </div>
                      <label class="layui-form-label">传真</label>
                      <div class="layui-input-inline">
                        <input type="text" name="fax" id="fax" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
                      </div> 
                      <label class="layui-form-label">卡号</label>
                      <div class="layui-input-inline">
                        <input type="text" name="cardNo" id="cardNo" required  lay-verify="required" placeholder="请输入输入框内容" autocomplete="off" class="layui-input">
                      </div> 
                    </div>
                    <div class="layui-form-item layui-form-text">
                      <label class="layui-form-label">地址</label>
                      <div class="layui-input-block">
                        <textarea name="address" id="address" placeholder="请输入内容" class="layui-input layui-tc" ></textarea>
                      </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                      <label class="layui-form-label">备注</label>
                      <div class="layui-input-block">
                        <textarea name="unitDescription" id="unitDescription" placeholder="请输入内容" class="layui-input layui-textarea layui-tc" ></textarea>
                      </div>
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                      <button class="layui-btn pear-btn-md pear-btn-primary layui-tc" style="position:absolute;right:5px;bottom:5px;" lay-submit lay-filter="formDemo">立即保存</button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div> 
        </form>
    
</body>

</html>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script src="../Script/getPingyin.js"></script>
<script>

    layui.use(['table', 'form', 'upload', 'layer', 'laydate', 'jquery', 'util', 'drawer', 'dropdown','popup'], function () {
        var table = layui.table,
            laydate = layui.laydate,
            form = layui.form,
            $ = layui.$,
            layer = layui.layer,
            upload = layui.upload
            , util = layui.util;
        let drawer = layui.drawer;
        let dropdown = layui.dropdown;
        var popup = layui.popup;

        //layer.msg(getUrlParam("id"));
        //alert(getUrlParam('name'));
        // $("#sjflmc").val(getUrlParam("name"));
         $("#id").val(getUrlParam("id"));
        //赋值
 //查询id查询商品信息
 $.ajax({
            type: "get",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            url: 'http://localhost:5161/api/BusinessUnit/GetUnitid?id=' + getUrlParam("id"),
            headers: {
                "Authorization": sessionStorage.getItem("token")
            },
            success: function (response) {
                //alert(response.result);
                var data = response.result;
                if (response.isSuccess) {
                    $("#unitName").val(data.unitName);
                    $("#unitNameJp").val(data.unitNameJp);
                    $("#category").val(data.category);
                    $("#goods_Gg").val(data.goods_Gg);
                    $("#companyPhone").val(data.companyPhone);
                    $("#address").val(data.address);
                    $("#fax").val(data.fax);
                    $("#cardNo").val(data.cardNo);
                    $("#unitDescription").val(data.unitDescription);
                    // alert(impathb + data.imgPath);
                    // document.getElementById('imgPath').src="impathb + data.imgPath";
                    // $("#imgPath").attr('src',impathb + data.imgPath);
                    // $("#imgPath2").attr('src',impathb + ddata.imgPath2);
                    // $("#imgPath3").attr('src',impathb + ddata.imgPath3);
                    // $("#imgPath4").attr('src',impathb + ddata.imgPath4);
                    form.render('select');
                } else {
                    popup.failure(response.result.msg);
                }

            }
        });
        //修改
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                type: "put",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                url: 'http://localhost:5161/api/BusinessUnit/PutUnit',
                data: JSON.stringify(data.field),
                headers: {
                    "Authorization": sessionStorage.getItem("token")
                },
                success: function (response) {
                    //alert(response.result);
                    if (response.result) {
                        parent.layer.msg("修改成功!", {time: 1000,icon: 1}, function () {
                            //重新加载父页面
                            parent.location.reload();

                            });
                    } else {
                        popup.failure("修改失败:" + data.msg);
                    }
                    
                }
            });
            return false;
        });
        //监听input文本可输入字数
        $(function(){
        //输入框的值改变时触发
        $("#unitName").on("input",function(e){
            //获取input输入的值
            //console.log(e.delegateTarget.value);
            $("#unitNameJp").val(pinyin.getCamelChars(e.delegateTarget.value));
        });
        });

    });
</script>